package com.huike.controller.report;

import com.huike.dto.ReportPageDto;
import com.huike.entity.*;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.ReportService;
import com.huike.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("admin/report")
public class ReportController {
    @Autowired
    private ReportService reportService;

    /**
     * 查询渠道
     *
     * @return Result<List < SysDictData>>
     */
    @GetMapping("/clues_item")
    public Result<List<SysDictData>> getChannelSource() {
        List<SysDictData> sysDictData = reportService.getSysDictData("clues_item");
        return Result.success(sysDictData);
    }

    /**
     * 客户统计查询
     *
     * @param beginDate LocalDate
     * @param endDate   LocalDate
     * @return Result<CustomerReportVo>
     */
    @GetMapping("/customerReport")
    public Result<CustomerReportVo> customerReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginDate,
                                                   @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        CustomerReportVo customerReportVo = reportService.customerReport(beginDate, endDate);
        return Result.success(customerReportVo);
    }


    /**
     * 查询学科客户统计
     *
     * @param beginDate LocalDate
     * @param endDate   LocalDate
     * @return Result<SubjectCustomerReportVo>
     */
    @GetMapping("/subjectReport")
    public Result<SubjectCustomerReportVo> subjectReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginDate,
                                                         @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        SubjectCustomerReportVo subjectCustomerReportVo = reportService.subjectCustomerReport(beginDate, endDate);
        return Result.success(subjectCustomerReportVo);
    }


    /**
     * 客户统计搜索
     *
     * @param dto ReportPageDto
     * @return Result<PageResult < Customer>>
     */
    @GetMapping("/customerReportSearch")
    public Result<PageResult<Customer>> customerReportSearch(ReportPageDto dto) {
        PageResult<Customer> pageResult = reportService.customerReportSearch(dto);
        return Result.success(pageResult);
    }

    /**
     * 销售额统计
     *
     * @param beginDate LocalDate
     * @param endDate   LocalDate
     * @return Result<SaleReportVo>
     */
    @GetMapping("/saleReport")
    public Result<SaleReportVo> saleReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginDate,
                                           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        SaleReportVo saleReportVo = reportService.saleReport(beginDate, endDate);
        return Result.success(saleReportVo);
    }

    /**
     * 销售分页查询
     *
     * @param dto ReportPageDto
     * @return Result<PageResult < Sale>>
     */
    @GetMapping("/saleReportSearch")
    public Result<PageResult<Sale>> saleReportSearch(ReportPageDto dto) {
        PageResult<Sale> pageResult = reportService.saleReportSearch(dto);
        return Result.success(pageResult);
    }


    /**
     * 线索统计
     *
     * @param beginDate LocalDate
     * @param endDate   LocalDate
     * @return Result<ClueReportVo>
     */
    @GetMapping("/clueReport")
    public Result<ClueReportVo> clueReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginDate,
                                           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        ClueReportVo clueReportVo = reportService.clueReport(beginDate, endDate);
        return Result.success(clueReportVo);
    }


    /**
     * 线索转化率统计
     *
     * @param beginDate LocalDate
     * @param endDate   LocalDate
     * @return Result<ClueInvertVo>
     */
    @GetMapping("/clueInvert")
    public Result<ClueInvertVo> clueInvert(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginDate,
                                           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        ClueInvertVo clueInvertVo = reportService.clueInvert(beginDate, endDate);
        return Result.success(clueInvertVo);
    }


    /**
     * 线索分页查询
     *
     * @param dto ReportPageDto
     * @return Result<PageResult < Clue>>
     */
    @GetMapping("/clueReportSearch")
    public Result<PageResult<Clue>> clueReportSearch(ReportPageDto dto) {
        PageResult<Clue> pageResult = reportService.clueReportSearch(dto);
        return Result.success(pageResult);
    }


    /**
     * 渠道客户统计
     *
     * @param beginDate LocalDate
     * @param endDate   LocalDate
     * @return Result<ChannelCustomerReportVo>
     */
    @GetMapping("/channelReport")
    public Result<ChannelCustomerReportVo> channelReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginDate,
                                                         @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        ChannelCustomerReportVo customerReportVo = reportService.channelReport(beginDate, endDate);
        return Result.success(customerReportVo);
    }

    /**
     * 渠道统计分页查询
     *
     * @param dto ReportPageDto
     * @return Result<PageResult < ChannelReport>>
     */
    @GetMapping("/channelReportSearch")
    public Result<PageResult<ChannelReport>> channelReportSearch(ReportPageDto dto) {
        PageResult<ChannelReport> pageResult = reportService.channelReportSearch(dto);
        return Result.success(pageResult);
    }

}
